package com.example.makerspace.dao;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.makerspace.domain.MeetingDO;
import com.example.makerspace.dto.PageRequest;
import com.example.makerspace.dto.Pagination;
import com.example.makerspace.mapper.MeetingMapper;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

@Component
public class MeetingDAO extends  BaseDAO<MeetingDO> {

    @Resource
    private MeetingMapper  meetingMapper;

    @PostConstruct
    public void init(){
        this.mapper = meetingMapper;
    }

    public IPage<MeetingDO> selectByPage(Pagination pagination) {
        QueryWrapper<MeetingDO> wrapper = new QueryWrapper<>();
        return mapper.selectPage(new Page<>(pagination.getPageNum(), pagination.getSize()), wrapper);
    }


    public IPage<MeetingDO> selectByPageAndCategory(Pagination pagination, String category) {
        QueryWrapper<MeetingDO> wrapper = new QueryWrapper<>();
        wrapper.eq("category",category);
        return mapper.selectPage(new Page<>(pagination.getPageNum(), pagination.getSize()), wrapper);
    }

    public List<MeetingDO> selectByViews() {
        QueryWrapper<MeetingDO> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("book_number").last("limit 4");
        return mapper.selectList(wrapper);
    }

    public IPage<MeetingDO> selectByPageAndClassify(Pagination pagination, String classify) {
        QueryWrapper<MeetingDO> wrapper = new QueryWrapper<>();
        wrapper.eq("classify",classify);
        return mapper.selectPage(new Page<>(pagination.getPageNum(), pagination.getSize()), wrapper);
    }

    public IPage<MeetingDO> selectByPageCategoryAndClassify(Pagination pagination, String category, String classify) {
        QueryWrapper<MeetingDO> wrapper = new QueryWrapper<>();
        wrapper.eq("classify",classify);
        wrapper.eq("category",category);
        return mapper.selectPage(new Page<>(pagination.getPageNum(), pagination.getSize()), wrapper);
    }
}
